const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('sunnyLogApi', {
    id: {
      autoIncrement: true,
      type: DataTypes.BIGINT,
      allowNull: false,
      primaryKey: true,
      comment: "编号"
    },
    tenantId: {
      type: DataTypes.STRING(12),
      allowNull: true,
      defaultValue: "000000",
      comment: "租户ID",
      field: 'tenant_id'
    },
    serviceId: {
      type: DataTypes.STRING(32),
      allowNull: true,
      comment: "服务ID",
      field: 'service_id'
    },
    serverHost: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "服务器名",
      field: 'server_host'
    },
    serverIp: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "服务器IP地址",
      field: 'server_ip'
    },
    env: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "服务器环境"
    },
    type: {
      type: DataTypes.CHAR(1),
      allowNull: true,
      defaultValue: "1",
      comment: "日志类型"
    },
    title: {
      type: DataTypes.STRING(255),
      allowNull: true,
      defaultValue: "",
      comment: "日志标题"
    },
    method: {
      type: DataTypes.STRING(10),
      allowNull: true,
      comment: "操作方式"
    },
    requestUrl: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "请求URI",
      field: 'request_url'
    },
    userAgent: {
      type: DataTypes.STRING(1000),
      allowNull: true,
      comment: "用户代理",
      field: 'user_agent'
    },
    ip: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "操作IP地址"
    },
    methodClass: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "方法类",
      field: 'method_class'
    },
    methodName: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "方法名",
      field: 'method_name'
    },
    params: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: "操作提交的数据"
    },
    time: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: "执行时间"
    },
    createBy: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: "创建者",
      field: 'create_by'
    },
    updateTime: {
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
      comment: "更新时间",
      field: 'update_time'
    },
    createTime: {
      type: DataTypes.DATE,
      allowNull: true,
      comment: "创建时间",
      field: 'create_time'
    },
    deleteTime: {
      type: DataTypes.DATE,
      allowNull: true,
      comment: "删除时间",
      field: 'delete_time'
    }
  }, {
    sequelize,
    tableName: 'sunny_log_api',
    timestamps: true,
    createdAt: 'createTime',
    updatedAt: 'updateTime',
    deletedAt: 'deleteTime',
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
    ]
  });
};
